package utils;

public class Vector extends Coordinates {

    public Vector(Vector vec) {
	super(vec.getX(), vec.getY(), vec.getZ());
    }

    public Vector(double[] cords) {
	super(cords[0], cords[1], cords[2]);
    }

    public Vector(double x, double y, double z) {
	super(x, y, z);
    }

    public Vector(Point3D p1, Point3D p2) {
	super(p2.getX() - p1.getX(), p2.getY() - p1.getY(), p2.getZ() - p1.getZ());
    }

    public Vector crossProduct(Vector vec) {
	double x = (this.getY() * vec.getZ()) - (this.getZ() * vec.getY());
	double y = (this.getZ() * vec.getX()) - (this.getX() * vec.getZ());
	double z = (this.getX() * vec.getY()) - (this.getY() * vec.getX());
	return new Vector(x, y, z);
    }

    public double dotProduct(Vector vec) {
	double x1 = this.getX();
	double y1 = this.getY();
	double z1 = this.getZ();

	double x2 = vec.getX();
	double y2 = vec.getY();
	double z2 = vec.getZ();

	return (x1 * x2 + y1 * y2 + z1 * z2);
    }

    public Vector scale(double factor) {
	return new Vector(this.getX() * factor, this.getY() * factor, this.getZ() * factor);
    }

    public Vector normalize() {
	double norma = getNorma();
	return new Vector(this.getX() / norma, this.getY() / norma, this.getZ() / norma);
    }

    public double getNorma() {
	double x = this.getX();
	double y = this.getY();
	double z = this.getZ();

	return Math.sqrt(x * x + y * y + z * z);
    }

    public boolean equals(Vector vec) {
	return (vec.getX() == this.getX() && vec.getY() == this.getY() && vec.getZ() == this.getZ());
    }

    public boolean isZero() {
	return this.equals(new Vector(0, 0, 0));
    }

    public Vector substract(Vector v1) {
	return new Vector(v1.getX() - this.getX(), v1.getY() - this.getY(), v1.getZ() - this.getZ());
    }

    public Vector add(Vector v1) {
	return new Vector(v1.getX() + this.getX(), v1.getY() + this.getY(), v1.getZ() + this.getZ());
    }
}
